package dynamicproxy;

import staticproxy.IStar;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author : cww
 * @date : 2021/1/13 22:06
 */
public class DynamicProxy<T> {
    public T getProxy(T t){
        return  (T)Proxy.newProxyInstance(t.getClass().getClassLoader(), t.getClass().getInterfaces(),
                new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        System.out.println("助手签合同");
                        Object result = method.invoke(t,args);
                        System.out.println("收线");
                        return result;
                    }
                });
    }
}
